from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

op = webdriver.ChromeOptions()
op.add_experimental_option("excludeSwitches",["enable-automation"])
op.add_experimental_option("useAutomationExtension",False)
diriver = webdriver.Chrome(options = op)

diriver.get(r"http://news.baidu.com/")

aList = diriver.find_elements(By.CSS_SELECTOR , "div#localnews-zixun > ul > li > a")
print(len(aList))
for i in aList:
    #print(i.text)
    content = i.text
    i.click()
    sleep(3)
    all_handles = diriver.window_handles
    diriver.switch_to.window(all_handles[1])
    print(diriver.title)
    atitle = diriver.title
    if len(content) > 20:
        content = content[0:20]
    assert content in atitle
    sleep(3)
    diriver.close()
    diriver.switch_to.window(all_handles[0])
    sleep(3)

diriver.quit()